package com.chf.control;

import com.chf.Bean.UserInfoBean;
import com.chf.model.MyModel;
import com.chf.utils.MyUtils;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "LoginServlet", value = "/LoginServlet")
public class LoginServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        List<UserInfoBean> list = MyModel.SeleteAllUserInfo();
        req.getSession().setAttribute("UserList",list);
        String userName = req.getParameter("userName");
        String userPwd = req.getParameter("userPwd");
        System.out.println(userName);
        System.out.println(userPwd);
        req.setAttribute("userName",userName);
        boolean bool = MyUtils.GetClass(MyModel.class).CanLogin(userName,userPwd);
        if (bool){
            req.getRequestDispatcher("WEB-INF/viewpages/loginedmain.jsp").forward(req,resp);

            //下拉框传值练习
//            resp.sendRedirect("select_test.jsp");
        }else {
            resp.sendRedirect("index.jsp");
        }
    }
}
